package com.qf.controller;

import com.qf.entity.Address;
import com.qf.service.AddressService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chen
 * @version 1.0
 * @date 2019/10/24 19:45
 */
@Controller
public class AddressController {
    @Resource
    private AddressService addressService;
    @ResponseBody
    @RequestMapping("/comment/addAddress")
    public Map addAddress(String receiverName,String phone,String addressDetail,
                          Integer addressStatus){
        Address address = new Address();
        address.setAddressname(addressDetail);
        address.setPhone(phone);
        address.setAddressstatus(addressStatus);
        address.setReceivername(receiverName);
        int i = addressService.insertAddress(address);
        Map map = new HashMap();
        if (i>0){
            map.put("code", 1);
            map.put("msg", "success");
        }else {
            map.put("code", 0);
            map.put("msg", "fail");
        }
        return map;
    }

    @ResponseBody
    @RequestMapping("/comment/deleteAddress")
    public Map deleteAddress(Integer addressId){
        int i = addressService.deleteAddress(addressId);
        Map map = new HashMap();
        if (i>0){
            map.put("code", 1);
            map.put("msg", "success");
        }else {
            map.put("code", 0);
            map.put("msg", "fail");
        }
        return map;
    }

}
